<template>
	<div>
		<div class="jumbotron">
			<form class="form-horizontal" role="form" @submit.prevent="">
				<div class="form-group">
					<div class="col-sm-offset-2 col-sm-10">
						<h1>简历管理</h1>
					</div>
				</div>
				<div class="col-sm-2"></div>
				<div class="form-group table-responsive col-sm-8">
					<table class="table">
						<thead align="right">
							<tr>
								<th>职位名</th>
								<th>姓名</th>
								<th>自我介绍</th>
								<th>最低意向薪金</th>
								<th>电子邮箱</th>
								<th>手机号</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
							<tr v-for="item in jobList">
								<td>{{item.jobName}}</td>
								<td>{{item.truename}}</td>
								<td>{{item.resumeContent}}</td>
								<td>{{item.salaryMin}}</td>
								<td>{{item.email}}</td>
								<td>{{item.mobile}}</td>
								<td>
									<button type="button" class="btn btn-success" @click="manageResume(item,0)">面试邀请</button>
									<button type="button" class="btn btn-danger" @click="manageResume(item,1)">拒绝简历</button>
								</td>
							</tr>
						</tbody>
					</table>
				</div>
			</form>
		</div>
	</div>
</template>

<script>
	module.exports = {
		mounted() {
			this.sysUser = JSON.parse(localStorage.getItem('sysUser'));
			$.ajax({
				url: conf.ur + "/api/enterprise/listAllResume?id=" + this.sysUser.id,
				type: 'get',
				dataType: 'json',
				headers: {
					"Content-Type": "application/json",
					"x-auth-token": window.localStorage.getItem('x-auth-token')
				},
				success: (data) => {
					console.log(data)
					console.log(JSON.stringify(data))
					if (data.code === 0) {
						this.jobList = data.data;
					} else {
						console.log("获取失败！")
					}
				},
				error: (err) => {
					console.log("网络异常！")
				}
			});
		},
		data: function() {
			return {
				sysUser: {
					id: 0,
				},
				jobList: []
			}
		},
		methods: {
			//type=0邀请 1拒绝
			manageResume(item, type) {
				if (type === 0) {
					if (confirm("确认发送面试邀请吗？") == true) {
						$.ajax({
							url: conf.ur + "/api/enterprise/manageResume?hunterId=" + parseInt(item.hunterId) + "&jobId=" + parseInt(item
								.jobId) + "&type=0",
							type: 'get',
							headers: {
								"Content-Type": "application/json",
								"x-auth-token": window.localStorage.getItem('x-auth-token')
							},
							success: (data) => {
								if (data.code === 0) {
									alert("发送成功！");
									window.location.reload();
								} else {
									alert("发送失败！")
									window.location.reload();
								}
							},
							error: (err) => {
								console.log("网络异常！")
							}
						});
					} else return false;
				} else {
					if (confirm("确认打回该简历吗？") == true) {
						$.ajax({
							url: conf.ur + "/api/enterprise/manageResume?hunterId=" + parseInt(item.hunterId) + "&jobId=" + parseInt(item
								.jobId) + "&type=1",
							type: 'get',
							headers: {
								"Content-Type": "application/json",
								"x-auth-token": window.localStorage.getItem('x-auth-token')
							},
							success: (data) => {
								console.log(JSON.stringify(data))
								if (data.code === 0) {
									alert("打回成功！");
									window.location.reload();
								} else {
									alert("打回失败！")
									window.location.reload();
								}
							},
							error: (err) => {
								console.log("网络异常！")
							}
						});
					} else return false;
				}
			},
		}
	}
</script>

<style scoped>
	.goodsImg {
		height: 100px;
	}

	.jumbotron {
		background-color: ghostwhite;
	}
</style>
